<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2021-02-07
 * Time: 13:56
 */

namespace app\api\service;


class VideoUpload
{
    private $filepath; //上传目录
    private $tmpPath; //PHP文件临时目录
    private $blobNum; //第几个文件块
    private $fileName; //文件名

    public function __construct($tmpPath,$blobNum,$fileName,$filepath)
    {
        $this->tmpPath = $tmpPath;
        $this->blobNum = $blobNum;
        $this->fileName = $fileName;
        $this->filepath = $filepath;
        $this->moveFile();
    }


    public function moveFile()
    {
        $this->touchDir();
        $filename = $this->filepath.'/'. $this->fileName.'__'.$this->blobNum;
        move_uploaded_file($this->tmpPath,$filename);
        return [
            'code' => 2000,
            'message'=> '操作成功',
            'data' => ''
        ];
    }

    // 判断是否有文件，没有进行创建
    private function touchDir()
    {
        if(!file_exists($this->filepath)){
            return mkdir($this->filepath);
        }
    }
}